package com.nage.components.movement;

import android.util.Log;

import com.nage.components.Component;
import com.nage.engine.GameObject;

public class RandomMovement extends Component {

	Physics physics;
	long lastChange;
//	private MultiplayerSystem ms;
	
	public RandomMovement(GameObject p) {
		super(p);
		type = RANDOM_MOVEMENT;
	}
	
	@Override
	public boolean findLinks() {
		physics = (Physics) parent.getComponent(PHYSICS);
		if(physics==null) {
			return false;
		}
		return true;
	}


	@Override
	public void update(long delta) {
		lastChange += delta;
		if(lastChange>100) {
//			physics.xVelocity = 0.05f - (float) Math.random()/5;
//			physics.yVelocity = 0.05f - (float) Math.random()/5;
		//	float x = (float) (0.1 - (float) Math.random() / 10);
		//	float y = (float) (0.1 - (float) Math.random() / 10);
		//	Log.d("RandomMovement", "adding constant force x = "+x+" y = "+y);
		//	physics.removeForce();
		//	physics.addImpulse(x, y);
			int rand = (int)(Math.random() * 2);
		//	Log.d("RandomMovement", "rand: "+rand);
			if(rand % 2 == 0) {
				parent.setX((float) (parent.x + 0.01));
				parent.setY((float) (parent.y + 0.01));
			} else {
				parent.setX((float) (parent.x - 0.01));
				parent.setY((float) (parent.y - 0.01));
			}
			lastChange = 0;
		//	Log.d("RandomMovement", "Tick");
		//	ms.send(new MultiplayerPacket("RANDOM_MOVEMENT TICK"));
		//	Log.d("RandomMovement", "X Velocity: "+physics.xVelocity+", Y Velocity: "+physics.yVelocity);
		//	Log.d("RandomMovement", "X Position: "+parent.getX()+", Y Position: "+parent.getY());
		}
	}

}
